package fox.framework.rpc.server.dispatcher.router;

import fox.framework.rpc.context.RpcObjectFactory;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author cuichao
 * @Description: DefaultRouteMapping
 * @Date: create in 2021/1/13 21:46
 */
public class DefaultRouteMapping implements RouteMapping {

    private String route;

    private Method invoker;

    private String instance;

    private RpcObjectFactory context;

    private DataBinder[] dataBinders = new DataBinder[0];

    public DefaultRouteMapping(RpcObjectFactory context, String route, Method invoker, String instance) {
        this.context = context;
        this.route = route;
        this.invoker = invoker;
        this.instance = instance;
        Parameter[] parameters = invoker.getParameters();
        if(parameters.length > 0){
            DataBinder[] db =new DataBinder[parameters.length];
            for (int i = 0 ; i < parameters.length; i++) {
                db[i] = new DataBinder(parameters[i]);
            }
        }
    }

    @Override
    public String getRoute() {
        return route;
    }


    @Override
    public Method getInvoker() {
        return invoker;
    }


    @Override
    public Object getTarget() {
        return context.getObject(instance);
    }

    @Override
    public DataBinder[] getDataBinders() {
        return dataBinders;
    }
}
